package com.solidit.cassandra.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.jdo.annotations.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.solidit.cassandra.controller.persistance.EventsDAO;
import com.solidit.cassandra.controller.persistance.model.Events;
import com.solidit.cassandra.service.SaveEventService;

@Controller
public class RegistrarEventoController {
    @Autowired
	private EventsDAO eventsDAO;
    @Autowired
    private SaveEventService saveEventService;

    
    @Transactional
	@RequestMapping(value = "/registrar_evento", method = RequestMethod.GET)
	public ModelAndView acceso() {
		List<Events> listaEventos = eventsDAO.getTypeEvent();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("listaEventos", listaEventos);
		Events e = new Events();
		map.put("command", e);
		return new ModelAndView("registrar_evento", map);
	}
    @Transactional
	@RequestMapping(value = "/registrar_evento", method = RequestMethod.POST)
	public ModelAndView salida(@ModelAttribute("command") Events e) {
		saveEventService.jsonEvent(e);

		
		return new ModelAndView("persona_registrada");
	}

}
